package utils;

import java.util.Vector;

public class CheckWorkerFinger extends RefreshBaseComm {
	private String identifyno;
	private String vendor;
	private String[] finger;
	private String identifyno2;
	
	private static final short FUNC_REQ_CHECKFINGER=21;
	private static final short FUNC_RET_CHECKFINGER=8021;
	
	public CheckWorkerFinger(String serverIp, int serverPort, 
			String identifyno, String vendor, String[] finger){
		super(serverIp, serverPort, FUNC_REQ_CHECKFINGER, 
				FUNC_RET_CHECKFINGER);
		this.identifyno = identifyno;
		this.vendor = vendor;
		this.finger = finger;
	}

	@Override
	protected Vector<Byte> MakePackBody() {
		Vector<Byte> data = new Vector<Byte>();
		data.clear();
		data.addAll(MakeField(identifyno));
		data.addAll(MakeField(vendor));
		for (int i=0; i<10; i++){
			String str = finger[i];
			if (str == null){
				str = "";
			}
			data.addAll(MakeField(str));
		}
		return data;
	}
	
	@Override
	protected void fetchData(int result, byte[] data, int pos){
		if (result != 6004){
			return;
		}
		
		int m = data[2];
		int n = data[3];
		
		if (m < 0){
			m += 0x100;
		}
		if (n < 0){
			n += 0x100;
		}
		
		short length =(short)(n*0x100+m);
		if (length > 0){
			identifyno2 = new String(data, 4, length);
		}
	}

	public String getIdentifyno2() {
		return identifyno2;
	}
}
